package ftGuard.network.l2.c2s;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import l2hc.gameserver.network.GameClient;
import l2hc.gameserver.network.clientpackets.L2GameClientPacket;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class GameGuardReply extends L2GameClientPacket
{
  private static final Logger _log = LoggerFactory.getLogger(GameGuardReply.class);
  private int _dx;
  private final byte[] _reply = new byte[8];
  private static final byte[] VALID = { -120, 64, 28, -89, -125, 66, -23, 21, -34, -61, 104, -10, 45, 35, -15, 63, -18, 104, 91, -59 };

  protected void readImpl()
  {
    readB(_reply, 0, 4);
    readD();
    readB(_reply, 4, 4);
  }

  protected void runImpl()
  {
    GameClient client = getClient();
    try
    {
      MessageDigest md = MessageDigest.getInstance("SHA");
      byte[] result = md.digest(_reply);
      if (Arrays.equals(result, VALID))
      {
        client.setGameGuardOk(true);
      }
    }
    catch (NoSuchAlgorithmException e)
    {
    }
  }

  public String getType()
  {
    return "[C] CB GameGuardReply";
  }
}